checkToken();
queryOperation();
function checkToken(){
	var systoken=sessionStorage.getItem('systoken');
	if(!systoken){
		layer.msg("请先登录!")
	window.location.href="login.html"
	}
}
$(".startSearch").click(function() {
	queryOperation();
})
//获取学员实操课培训记录
function queryOperation() {	
	//渲染
	var name = sessionStorage.getItem('name');
	var stamp = new Date().getTime();
	var operationType=$(".operationType option:selected").val();
	var number = $(".number").val();
	var startTime=$(".startTime").val();
	var endTime = $(".endTime").val();
	var systoken = sessionStorage.getItem('systoken');
	layui.use(['table', 'laypage', 'layer', 'laydate','jquery'], function() {
		var laypage = layui.laypage,
			layer = layui.layer,$=layui.jquery;
		var table = layui.table;
		var laydate = layui.laydate;
		//渲染
		var stamp = new Date().getTime();
		var systoken = sessionStorage.getItem('systoken');
		// var gender = gender
		var param = {	
			studentName:name,
	//		theoryName:theoryName,
			operationType:operationType,
			number:number,
			startTime:startTime,
			endTime:endTime,
			stamp: stamp,
			systoken: systoken,
			version: 0,
			visit_plat: 1,
			visit_type: 0,
			is_used: 0
		};
		param = JSON.stringify(param);
		var url = path+"/operationRecords/getAll";
		var defaultpageSise = 10;
		window.ins1 = _render(defaultpageSise);
		function _render(pageSize) {
			var width  =$(document).width();
		table.render({
			elem: '#shiChaopTest',
			height: 600,
			title: '实操课培训记录',
			method: 'post',
			url: url,
			page: true,
			where: {param: param},
            headers:{Authorization:systoken},
			skin: 'row',
			even: true,
			// autoSort: true,
			loading: false,
			parseData: function(res) {
				var msg
				if(res.status=='000'){
					msg=res.info;
					var data = res.rows
					for(i = 0; i < data.length; i++) {
						var gender = data[i].gender
						if(gender == 0) {
							data[i].gender = '男';
						} else {
							data[i].gender = '女';
						}
					}
				}else if(res.rows=='后台数据为空'){
					msg='后台数据为空';
				}
				return {
					"code": res.status,
					"msg": msg,
					"count": res.total,
					"data": res.rows
				};
			},
			done: function(res) {
				$('#inp').val(pageSize);
				$("#inp").on('blur', function() {
				      var inputVal = $("#inp").val();
				      _render(inputVal);
				 });
			},
			totalRow: true,
			limit: 30,
			width:width*0.9,
			cols: [
					{
						field: 'teacherName',
						title: '教员名称',
						width:'30%',align: 'center'
					},
					{
						field: 'studentName',
						title: '学员名称',
						width:'30%',align: 'center'
					},
					{
						field: 'operationType',
						title: '培训科目',
						width:'30%',align: 'center',
						 templet : '#operationType'
					},
					{
						field: 'number',
						title: '练习编号',
						width:'30%',align: 'center'
					},
					{
						field: 'totalScore',
						title: '得分',
						width:'30%',align: 'center'
					},
					{
						field: 'createTime',
						title: '时长',
						width:'100',align: 'center'
					},
			],
			page: true,
			limits: [10, 20, 30, 40, 50, 100],
			limit: pageSize,
			loading: true
		});
	};
		//日期时间选择器
		laydate.render({
			elem: '.createTime',
			type: 'datetime'
		});
		laydate.render({
			elem: '.updateTime',
			type: 'datetime'
		});
		laydate.render({
			elem: '.birthday',
			type: 'datetime'
		});
		laydate.render({
			elem: '.startTime',
			type: 'date'
		});
		laydate.render({
			elem: '.endTime',
			type: 'date'
		});
		//日期时间选择器结束
		// 工具栏事件
		table.on('toolbar(shiChaopTest)', function(obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			var exportExel = table.checkStatus('shiChaopTest').data;
			switch(obj.event) {
				case 'add':
					layer.msg('添加');
					break;
				case 'update':
					layer.msg('编辑');
					break;
				case 'delete':
					layer.msg('删除');
					break;
				case 'getCheckData':
					var deletData = checkStatus.data;
					exportExel = checkStatus.data;
					deletChecked(deletData);
					break;
				case 'getCheckLength':
					var data = checkStatus.data;
					layer.msg('选中了：' + data.length + ' 个');
					break;
				case 'isAll':
					layer.msg(checkStatus.isAll ? '全选' : '未全选')
					break;
				case 'LAYTABLE_EXPORT':
					table.exportFile('shiChaopTest', exportExel, 'xls');
					break;
			};
		});

		var $ = layui.jquery,
			active = {
				parseTable: function() {
					table.init('parse-table-demo', {
						limit: 3
					});
				},
				add: function() {
					table.addRow('shiChaopTest')
				}
			};
		$('i').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});
		$('.layui-btn').on('click', function() {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		})
	});
}
//监控键盘事件
//watchKeybord() {
//  var me = this
//  var oriWinHeight = window.innerHeight
//  window.onresize = function() {
//      me.isKeybordAvail = true
//      var newHeight = window.innerHeight
//      // 阀值大于140判断为键盘收起
//      if (newHeight - oriWinHeight > 140) {
//          me.oprNum('input')
//      }
//      oriWinHeight = newHeight
//  }
//}

sessionStorage.removeItem("menu");
sessionStorage.removeItem("curMenu");